package day9;

import java.util.SimpleTimeZone;

class Factorial implements Runnable {
    private int num;
    private static int result;
    public Factorial(int num) {
        super();
        this.num = num;
    }
    @Override
    public void run() {
        synchronized(Factorial.class) {
            int multiply = multiply(this.num);
            System.out.println(this.num + "的阶乘为：" + multiply);
        }
    }
    private int multiply(int num) {
        if (num == 1) {
            return 1;
        } else {
            return num * multiply(num - 1);
        }

    }

}
public class ThreadWork {
    public static void main(String[] args) {
        Factorial fa1 = new Factorial(10);
        Factorial fa2 = new Factorial(8);
        Factorial fa3 = new Factorial(5);
        Thread t1 = new Thread(fa1);
        Thread t2 = new Thread(fa2);
        Thread t3 = new Thread(fa3);

        t1.start();
        t2.start();
        t3.start();
    }
}
